import redis


class MyRedis:
    def __init__(self, host='localhost', port=6379, db=0):
        self.redis = redis.Redis(host=host, port=port, db=db)

    # 字符串的添加
    def set_str(self, key, value):
        self.redis.set(key, value)

    def set_time_str(self, key, time, value):
        self.redis.setex(key, time, value)

    def get(self, key):
        return self.redis.get(key)

    def delete(self, key):
        self.redis.delete(key)

    def exists(self, key):
        return self.redis.exists(key)

    def keys(self, pattern='*'):
        return self.redis.keys(pattern)

    def flushdb(self):
        self.redis.flushdb()
